package com.zlx.xbhy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zlx.xbhy.entity.User;
import com.zlx.xbhy.mapper.UserMapper;
import com.zlx.xbhy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Author 周罗校
 * @Description
 * @ClassName UserServiceImpl
 * @date 2020.11.17 19:48:07
 * 该版权归周罗校所有，最终解释权以官方为准
 */
@Service
@Transactional
public class UserServiceImpl extends BaseServiceImpl<User, Long> implements UserService {
    @Autowired
    private UserMapper mapper;

    /***
     * @Author 周罗校
     * @Description 查询分页
     * @Param [username, start, pageSize]
     * @return com.github.pagehelper.PageInfo<com.zlx.xbhy.entity.User>
     * @Date 2020.11.18 14:52:02
     **/
    @Override
    public PageInfo<User> selectPage(String username, Integer start, Integer pageSize) {
        PageHelper.startPage(start, pageSize);
        User user = new User();
        return new PageInfo<>(mapper.selectPage(username));
    }

    /***
     * @Author 周罗校
     * @Description 查询已关注用户分页
     * @Param [userId, start, pageSize]
     * @return com.github.pagehelper.PageInfo<com.zlx.xbhy.entity.User>
     * @Date 2020.11.18 14:52:19
     **/
    @Override
    public PageInfo<User> selectFocusUsers(Long userId, Integer start, Integer pageSize) {
        PageHelper.startPage(start, pageSize);
        User user = new User();
        return new PageInfo<>(mapper.selectFocusUsers(userId));
    }

    /**
     * @return java.util.List<com.zlx.xbhy.entity.User>
     * @Author 周罗校
     * @Description 查询共同关注用户和同时收藏文章
     * @Param [uId, aId]
     * @Date 2020.11.18 18:24:06
     **/
    @Override
    public List<User> selectMulFavoriteUser(Long uId, Long aId) {
        return mapper.selectMulFavoriteUser(uId, aId);
    }

    /**
     * @return java.util.List<com.zlx.xbhy.entity.User>
     * @Author 周罗校
     * @Description 查询最近七天用户的添加数
     * @Param []
     * @Date 2020.11.24 20:27:40
     **/
    @Override
    public List<User> countNew() {
        List<User> list = new ArrayList<>();
        Collections.addAll(list, mapper.countNew(0), mapper.countNew(1),
                mapper.countNew(2), mapper.countNew(3), mapper.countNew(4),
                mapper.countNew(5), mapper.countNew(6),mapper.countNew(7),mapper.countNew(8));
        Collections.reverse(list);
        return list;
    }


}
